"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const koa2_cors_1 = __importDefault(require("koa2-cors"));
const koa_compress_1 = __importDefault(require("koa-compress"));
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
const resourcesProxy_1 = __importDefault(require("./proxy/resourcesProxy"));
const errHandler_1 = __importDefault(require("./lib/errHandler"));
const AppFileRoutes_1 = __importDefault(require("../routes/AppFileRoutes"));
const ProxyRoutes_1 = __importDefault(require("../routes/ProxyRoutes"));
const DBRoutes_1 = __importDefault(require("../routes/DBRoutes"));
const AuthorizeRoutes_1 = __importDefault(require("../routes/AuthorizeRoutes"));
const configTool_1 = __importDefault(require("../com/configTool"));
const logHandler_1 = __importDefault(require("./lib/logHandler"));
const IPAuthorityHandler_1 = __importDefault(require("./lib/IPAuthorityHandler"));
const MapServicesRoutes_1 = __importDefault(require("../routes/MapServicesRoutes"));
const TileRoutes_1 = __importDefault(require("../routes/TileRoutes"));
const plugsRoutes_1 = __importDefault(require("../../plug/router/plugsRoutes"));
var RouteType;
(function (RouteType) {
    RouteType["client"] = "client";
    RouteType["manage"] = "manage";
})(RouteType || (RouteType = {}));
function clientMiddleWare(app) {
    configTool_1.default.baseConfig.clientCORS && app.use((0, koa2_cors_1.default)());
    app.use((0, koa_bodyparser_1.default)());
    app.use((0, errHandler_1.default)());
    app.use((0, logHandler_1.default)(RouteType.client));
    app.use((0, IPAuthorityHandler_1.default)(['*'], configTool_1.default.baseConfig.clientBlackList));
    app.use((0, koa_compress_1.default)({ br: false }));
    (0, resourcesProxy_1.default)(app, configTool_1.default.wwwPath);
    app.use(ProxyRoutes_1.default.routes());
    app.use(MapServicesRoutes_1.default.routes());
    app.use(AppFileRoutes_1.default.routes());
    app.use(DBRoutes_1.default.routes());
    app.use(TileRoutes_1.default.routes());
    app.use(AuthorizeRoutes_1.default.routes());
    for (let i = 0; i < plugsRoutes_1.default.length; i++) {
        app.use(plugsRoutes_1.default[i].routes());
    }
}
exports.default = clientMiddleWare;
